<!--复制订单信息  -->
<template>
  <view>
    <u-popup v-model="copyOrderShow" mode="bottom" border-radius="24" @maskClick="_close()">
      <view>
        <view class="headTitle tc fw5 fz-16">复制订单信息</view>
        <scroll-view scroll-y class="listBody"> 
          <view class="u-padding-left-32 u-padding-right-32 linh-48 u-flex u-row-between" v-for="(item,idx) in copyReasons" :key="idx">
            <view @click.stop="_otherReasonsChange(item)" style="flex:1;">{{item.label}}</view>
            <u-checkbox v-model="item.check" active-color="#E44435" shape="circle" wrap></u-checkbox>
          </view>
        </scroll-view>
        <view class="themeBgColor configBtn" @click="_configCopy">确认复制</view>
        <view class="safe-bottom"></view>
      </view>
		</u-popup>
  </view>
</template>

<script>
import { comparedValue, orderStatus } from "@/utils/statusList"
import orderApi from "@/api/orderApi.js";

export default {
  props: {
    show: {type: Boolean, default: false},
    copyObj: {type: Object, default: {}}
  },
  watch:{
    show(val){
      this.copyOrderShow = val
    }
  },
  computed: {
    isCheck(){
      const item = this.copyReasons.find(v=> {
        return v.check === true
      })
      return !!item     
    }
  },
  data () {
    return {
      copyOrderShow: false,
      copyReasons: [
        {
          label: "跟团号",
          check: false
        },
        {
          label: "订单编号",
          check: false
        },
        {
          label: "订单状态",
          check: false
        },
        {
          label: "团员微信昵称",
          check: false
        },
        {
          label: "商品信息",
          check: false
        },
        {
          label: "快递单号",
          check: false
        },
        {
          label: "收货信息",
          check: false
        },
        {
          label: "买家备注",
          check: false
        }
      ]
    }
  },
  methods:{
    // 切换取消原因
    _otherReasonsChange(item){
      item.check = !item.check
    },
    // 确定复制
    async _configCopy(){
      if(!this.isCheck) return
      let params = ``
      if(this.copyReasons[0].check){
        params += `跟团号：${this.copyObj.followGroupNum}\n`
      }
      if(this.copyReasons[1].check){
        params += `订单编号：${this.copyObj.orderAllId}\n`
      }
      if(this.copyReasons[2].check){
        params += `订单状态：${comparedValue(orderStatus,this.copyObj.status)}\n`
      }
      if(this.copyReasons[3].check){
        params += `团员微信昵称：${this.copyObj.nickname}\n`
      }
      if(this.copyReasons[4].check){
        // params += `商品信息：\n`
        if(this.copyObj.orderGoodsRespVOList){
          this.copyObj.orderGoodsRespVOList.forEach(v=>{
            params += `商品信息：${v.goodsName}\n`
            params += `商品规格：${v.skuName.replace('^^','/')}\n`
            params += `商品数量：${v.count}\n`

          })
        }
        if(this.copyObj.orderGoodsDetailsRespVOList){
          this.copyObj.orderGoodsDetailsRespVOList.forEach(v=>{
            params += `商品信息：${v.goodsName}\n`
            params += `商品规格：${v.skuName.replace('^^','/')}\n`
            params += `商品数量：${v.count}\n`

          })
        }
      }
      if(this.copyReasons[5].check){
        params += `快递单号：` 
        try {
          // 获取快递单号
          const { data } = await orderApi.getLogistics({orderAllId: this.copyObj.orderAllId})
          if(data && data.length){
            data.forEach(v=>{
                params += `${v.logisticsName}：${v.logisticsCode} \n`
            })
          }else{
            params += `暂无\n`
          }
        } catch (error) {
          params += `\n`
          console.log('快递单号获取失败');
        }
      }
      if(this.copyReasons[6].check){
        params += `收货信息：${this.copyObj.receiveName} ${this.copyObj.receiveMobile} ${this.copyObj.receiveAddress}\n`
      }
      if(this.copyReasons[7].check){
        params += `备注：${this.copyObj.remark || '暂无'}\n`
      }


      const that = this
      if(params){
        uni.setClipboardData({
          data: params,
          showToast: false,
          success: function () {
            uni.showToast({
              title: '订单已复制',
              icon: 'success'
            });
            that.copyOrderShow = false
            that._close()
          }
        });
      }else{
        that.copyOrderShow = false
        that._close()
      }
    },
    _close(){
        this.$emit('close')
    }
  }
}
</script>
<style lang="scss" scoped>
.headTitle{
  line-height: 116rpx;
}
.configBtn{
  margin:0 32rpx;
  margin-top: 20rpx;
  border-radius: 93rpx;
  line-height: 96rpx;
  text-align: center;
  color: #FFF;
}

</style>